package com.sinozo.data.utils;

import com.sinozo.data.common.DataConfig;
import org.apache.commons.lang3.StringUtils;

public class ClickhouseUtil {



    public static String getUserRegisterLookUpDDL() {
        return "create table `user_register`( " +
                "`os` string, " +
                "`code` string, " +
                "`device_id` string, " +
                "`register_time` timestamp, " +
                "`create_time` timestamp, " +
                " primary key(`device_id`) not enforced " +
                ")" + ClickhouseUtil.clickhouseLookUpTableDDL("dws_user_register_window");
    }


    public static String clickhouseLookUpTableDDL(String tableName) {
        return " WITH ( " +
                "'connector' = 'clickhouse', " +
                "'url' = '" + DataConfig.CLICKHOUSE_SERVER + "', " +
                "'database-name' = '" + DataConfig.CLICKHOUSE_DATABASE + "', " +
                "'table-name' = '" + tableName + "', " +
                getUserName(DataConfig.CLICKHOUSE_USER) +
                getPassword(DataConfig.CLICKHOUSE_PASSWORD) +
//                "'lookup.partial-cache.max-rows' = '10'," +
//                "'lookup.partial-cache.expire-after-write' = '1 hour'," +
                "'sink.batch-size' = '500' " + ", " +
                "'sink.flush-interval' = '1000' " + ", " +
                "'sink.max-retries' = '3' " +
                ")";
    }


    public static String getPassword(String password) {
        if (!StringUtils.isEmpty(password)) {
            return  "'password' = '" + password + "', ";
        }
        return "";
    }

    public static String getUserName(String userName) {
        if (!StringUtils.isEmpty(userName)) {
           return  "'username' = '" + userName + "', ";
        }
        return "";
    }

}